﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Repository;

namespace FRL.DebtChased.Silverlight.Library
{

	/// <summary>
	/// Declaration of PointActiveButton class
	/// Button for displaying state of a contact point
	/// </summary>
	public partial class PointActiveButton : UserControl
	{

		/////////////////////////////////////////////////////////////
		// Delegates and events

		public event EventHandler Click;

		/////////////////////////////////////////////////////////////
		// Dependency properties

		public static readonly DependencyProperty PointStateProperty;

		/////////////////////////////////////////////////////////////
		// Enumerations

		/////////////////////////////////////////////////////////////
		// Attributes

		public Definitions.eContactPointStatus PointState
		{
			get
			{
				return (Definitions.eContactPointStatus)GetValue(PointStateProperty);
			}
			set
			{
				SetValue(PointStateProperty, value);
			}
		}

		/////////////////////////////////////////////////////////////
		// Construction

		static PointActiveButton()
		{

			// Register dependency properties
			PointStateProperty = DependencyProperty.Register(
				"PointState",
				typeof(Definitions.eContactPointStatus),
				typeof(PointActiveButton),
				new PropertyMetadata(Definitions.eContactPointStatus.NotSet, PointStateChanged)
			);

		}

		public PointActiveButton()
		{

			// Load xaml resources
			InitializeComponent();

		}

		/////////////////////////////////////////////////////////////
		// Dependency property - Event handlers

		private static void PointStateChanged(DependencyObject element, DependencyPropertyChangedEventArgs e)
		{

			// Set point state
			((PointActiveButton)element)._setPointState((Definitions.eContactPointStatus)e.NewValue);

		}

		/////////////////////////////////////////////////////////////
		// Events

		private void MainButton_Click(object sender, RoutedEventArgs e)
		{

			// Pass click event onto handlers
			if (Click != null)
				Click(sender, e);

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setPointState(Definitions.eContactPointStatus pointState)
		{

			// Select the style for the state
			switch (pointState)
			{
				case Definitions.eContactPointStatus.Active:
					MainButton.Style = this.Resources["ActiveStyle"] as Style;
					break;
				case Definitions.eContactPointStatus.Dead:
					MainButton.Style = this.Resources["InactiveStyle"] as Style;
					break;
				default:
					MainButton.Style = this.Resources["UnknownStyle"] as Style;
					break;
			} // switch

		}

	}

}
